package cn.eud.hunau.controller;

import cn.eud.hunau.common.BindingResultParseMessage;
import cn.eud.hunau.common.R;
import cn.eud.hunau.pojo.User;
import cn.eud.hunau.request.UserReq;
import cn.eud.hunau.service.UserService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author hb
 * @date 2025-06-18 16:41:48
 */
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserService userService;

    @PostMapping("/login")

    public R login(@RequestBody   @Valid UserReq user, BindingResult bindResult){

        if(bindResult.hasErrors()){
            return R.error().message(BindingResultParseMessage.parseDefaultMessage(bindResult));
        }


       User u= userService.login(user);
       return R.ok().data("user",u);
    }
}
